package com.chixing.day13_list.work;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProductTwoTest {
    public static void main(String[] args) {
        List<Producttwo> list = new ArrayList<>();
        list.add( new Producttwo("宝洁","洗手粉",18.5));
        list.add( new Producttwo("联合利华","肥皂",4.5));
        list.add( new Producttwo("宝洁","牙膏",32.5));
        list.add( new Producttwo("洁利","洗面奶",26.0));
        list.add( new Producttwo("洁利","洗面奶",24.0));
        list.add( new Producttwo("好迪","洗发水",27.5));
        list.add( new Producttwo("多芬","沐浴露",38.5));
        list.add( new Producttwo("宝洁","洗洁精",3.4));

        Map<String,Double> map = new HashMap<>();
        for (int i=0;i<list.size()-1;i++){
            double sum =0;
            for (int j=i;j<list.size();j++){
                if (list.get(i).getBrand().equals(list.get(j).getBrand()))
                    sum+=list.get(j).getCost();
            }
            if (!map.containsKey(list.get(i).getBrand())){
                map.put(list.get(i).getBrand(),sum);
            }
        }
        System.out.println(map);
        System.out.println(map.get("宝洁"));
    }
}
